Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Cannot use placeholder {TOKEN:ATTRIBUTE_5} on question.

More
7 years 5 months ago #166889 by mfiora
Hello,
i need to use {TOKEN:ATTRIBUTE_5} value in a question to condition answers. Any place holder, like {TOKEN:FIRSTNAME}, doesn't give back any value.
I'm on version 2.73.1+171220.

This is what i'm trying to do:
Code:
<script type="text/javascript" charset="utf-8">
 
   $(document).ready(function() {
 
     var gruppoPa = '{TOKEN:ATTRIBUTE_5}'.substring(7, 5).toUpperCase();
 
gruppoa = gruppoa.substring(7,5).toUpperCase();
 
       $('select[id^="answer"] option').each(function(i){
 
           if($(this).attr('value') &amp;&amp; $(this).attr('value').substr(0, 2).toUpperCase() != gruppoa) {
               $(this).remove();
           }
       });
   });
 
   </script>

If this cannot be done how can i workaround it?

Thanks,
The topic has been locked.
More
7 years 5 months ago #166892 by Joffm
Hi,
what I saw is
Code:
gruppoa = gruppoa.substring(7,5).toUpperCase();
"gruppoa" is not defined.
Maybe there is a typo and all variables are "gruppoa".
Code:
var gruppoPa = '{TOKEN:ATTRIBUTE_5}'.substring(7, 5).toUpperCase();
then gruppoPa is a 5 character string.

But then the next line which again tries to get a substring(7,5) out of a string which is only 5 characters long, will fail.

And in the rest of your script you use the not defined "gruppoa".

But without more knowledge what you are trying to do,...?
Can't you provide a sample of the problematic questions? *.lss

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
7 years 5 months ago #166897 by mfiora
Hello Joffm and thanks for your reply,
in the rendered page i cannot see the value of {TOKEN:ATTRIBUTE_5} so it's not a matter of typo. All i see is:
Code:
var gruppoa = '';

The script compares the first 2 letters in the answer code with 2 specific letters in the {TOKEN:ATTRIBUTE_5}. If they are not the same the answer is removed from the list.

If i set the gruppoa value manually the script works great.
You can see attached a .lsq file renamed to txt.

Thank you very much.
The topic has been locked.
More
7 years 4 months ago - 7 years 4 months ago #166923 by Joffm
Hi,
now in your *.lsq the script is different from the first one.

lsq:
Code:
$(document).ready(function() {
 
      var gruppoa = '{TOKEN:ATTRIBUTE_5}';
      gruppoa = gruppoPa.substring(7,5).toUpperCase();

and

original:
Code:
$(document).ready(function() {
 
     var gruppoPa = '{TOKEN:ATTRIBUTE_5}'.substring(7, 5).toUpperCase();
 
gruppoa = gruppoa.substring(7,5).toUpperCase();

But:
What is "gruppoPa" in your *.lsq script?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 7 years 4 months ago by Joffm.
The topic has been locked.
More
7 years 4 months ago #166926 by mfiora
I'm sorry Joffm,
gruppoa and gruppoPa are the same variable. I deleted the P before posting here.
Beside that on the rendered page i see this:
Code:
<script>
 
   $(document).ready(function() {
 
      var gruppoa = "";
     gruppoa = gruppoa.split("_")[1];
     gruppoa = gruppoa.substr(0,2).toUpperCase();
 
       $('select[id^="answer"] option').each(function(i){
 
           if($(this).attr('value') &amp;&amp; $(this).attr('value').substr(0,2).toUpperCase() != gruppoa) {
               $(this).remove();
           }
       });
   });
 
   </script>

I know this is still different. I'm trying to change to see if it works. I really think the problem is the {TOKEN:ATTRIBUTE_5} value not showing the "var gruppoa = " line.

Thank you very much. Your help is very appreciated.
The topic has been locked.
More
7 years 4 months ago #166946 by mfiora
Hello,
just for testing i got rid of the javascript and only i left
Code:
Indicare la vostra scelta {TOKEN:ATTRIBUTE_5}
in the question field.

The attribute is still not visible.
Thanks.
The topic has been locked.
More
7 years 4 months ago #166948 by tpartner
Can you attach a small test survey in .lss format?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 4 months ago #166952 by mfiora
Hello tpartner,
i prepared the small test survey and then i tested it. It works there. :(
I mean, i can see the value of the {TOKEN:ATTRIBUTE_5} on the HTML source.
I thought it could be template-related so i set the same template on the real survey and still works.
So i suppose it's a problem on the real survey, which is huge.
Anyone can help me with that?
Thanks,
The topic has been locked.
More
7 years 4 months ago #166956 by tpartner
Are you sure that the survey is non-anonymous?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 4 months ago #166957 by mfiora
Hello tpartner,

Impostazioni dell'indagine: Le risposte a questa indagine NON sono anonime.

Survey settings: The answers for this survey are NOT anonymous.

Thanks,

regards,
The topic has been locked.
More
7 years 4 months ago #166959 by mfiora
Hello,
here's another clue: i copied the survey structure to another survey.
Without activating it i clicked on "Run survey with this participant" and it worked.
Then i activated the survey and it didn't work.
Again i deactivated the survey, imported participants, took the survey and it worked.

What can i check?

Thanks,
The topic has been locked.
More
7 years 4 months ago #166960 by Joffm
Hello, mfiora,

could you please send your test survey resp. the interesting part as *.lss

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
7 years 4 months ago #166961 by mfiora
Here it is, i hope i've done it correctly.
The topic has been locked.
More
7 years 4 months ago #166962 by mfiora
You should see opla_asti on the question. If you don't you have my same problem.
The topic has been locked.
More
7 years 4 months ago - 7 years 4 months ago #166963 by Joffm
Hi, I created a participants table with the 5th attribute as "12345co89"

Activated the survey "not anonymous".

Then I get as "gruppoa" -> "CO"
and in the dropdown there are only the items with codes starting with "CO"


and a second with attribute "12345az89"





So it seems to work. I hope I understood correctly.

This seems to be really strange.

Hopefully Tony can investigate further.

All the best
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 7 years 4 months ago by Joffm.
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose